package com.artist.controller;

import com.artist.entity.TbWork;
import com.artist.service.WorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.PanelUI;
import java.util.List;

@Api(tags = "作品管理" )
@RestController
public class workController {
    @Autowired
    private WorkService service;

    @ApiOperation(value = "作品列表")
    @GetMapping("/work")
    public List<TbWork> workAll() {
        List<TbWork> list = service.workAll();
        System.out.println(list);
        return list;
    }

    @ApiOperation(value = "单个作品")
    @GetMapping("/work/{id}")
    public TbWork getWorkByPrimaryKey(@PathVariable Long id) {
        TbWork tbWork = service.selectWorkByPrimaryKey(id);
        System.out.println(tbWork);
        return tbWork;
    }

    @ApiOperation(value = "增加作品")
    @PostMapping("/work")
    public String insertWork(@RequestBody TbWork tbWork) {
        service.saveWork(tbWork);
        return "edit";
    }

    @ApiOperation(value =  "编辑作品")
    @PutMapping("/work/{id}")
    public String updateWorkByPrimaryKey(@RequestBody TbWork tbWork) {
       service.updateWork(tbWork);
        return "allwork";
    }
    @ApiOperation("删除作品")
    @DeleteMapping("/work/{id}")
    public String deleteWorkByPrimaryKey(@PathVariable Long id) {
        service.deleteWordByPrimaryKey(id);
        return "allwork";
    }

}
